package com.csh.auth.common.entity;

import com.csh.auth.common.enums.ResultCodeEnum;
import lombok.Data;

@Data
public class Result<T> {

    private Boolean success;

    private Integer code;

    private String message;

    private T data;

    public Result() {
        this.code = ResultCodeEnum.SUCCESS.getCode();
        this.message = ResultCodeEnum.SUCCESS.getMsg();
    }


    public static Result ok(){
        Result result = new Result();
        result.setSuccess(true);
//        result.setCode(ResultCodeEnum.SUCCESS.getCode());
//        result.setMessage(ResultCodeEnum.SUCCESS.getMsg());
        return result;
    }

    public static <T> Result ok(T data) {
        Result result = new Result();
        result.setSuccess(true);
        result.setData(data);
        return result;
    }

    public static Result fail(){
        Result result = new Result();
        return result.error(ResultCodeEnum.FAIL.getCode(),ResultCodeEnum.FAIL.getMsg(),false);
    }

    public static <T> Result fail(T data) {
        Result result = new Result();
        result.error(ResultCodeEnum.FAIL.getCode(),ResultCodeEnum.FAIL.getMsg(),false);
        result.setData(data);
        return result;
    }

    public Result<?> error(Integer code, String msg, Boolean success) {
        this.code = code;
        this.message = msg;
        this.success = success;
        return this;
    }
}
